package com.caption.mq.listener;

import com.caption.mq.entity.ModelResult;
import com.caption.mq.entity.MqMessageDTO;
import com.caption.mq.entity.MqSubscribeDO;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.web.client.RestTemplate;

/**
 * 处理MQ消息监听器
 */
public abstract class AbstractMqListener {

    private final MqSubscribeDO mqSubscribeDO;


    public AbstractMqListener(MqSubscribeDO mqSubscribeDO, RestTemplate restTemplate) {
        this.mqSubscribeDO = mqSubscribeDO;
    }
    /**
     * TODO 通过restTemplate请求各个模块子接口
     * @param messageDTO
     * @return
     */
    public ModelResult handleMessage(MqMessageDTO messageDTO){

       return null;
    }

    /**
     * 处理成功消息
     * @param messageExt
     * @param messageDTO
     * @param modelResult
     */
    abstract  public void onMessageHandleSuccess(MessageExt messageExt, MqMessageDTO messageDTO, ModelResult modelResult);

    /**
     * 处理失败消息
     * @param messageExt
     * @param messageDTO
     * @param modelResult
     */
    abstract  public void onMessageHandleFailed(MessageExt messageExt, MqMessageDTO messageDTO, ModelResult modelResult);

    /**
     * 处理异常消息
     * @param messageExt
     * @param messageDTO
     * @param e
     */
    abstract  public void onMessageHandleException(MessageExt messageExt, MqMessageDTO messageDTO, Exception e);
}
